package com.tledu.store.controller;

import com.tledu.common.annotation.Log;
import com.tledu.common.core.controller.BaseController;
import com.tledu.common.core.domain.AjaxResult;
import com.tledu.common.core.page.PageDomain;
import com.tledu.common.core.page.TableDataInfo;
import com.tledu.common.enums.BusinessType;
import com.tledu.common.utils.poi.ExcelUtil;
import com.tledu.store.domain.StoreLog;
import com.tledu.store.domain.vo.StoreLogVO;
import com.tledu.store.service.IStoreLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 库房日志Controller
 * 
 * @author ruoyi
 * @date 2024-08-29
 */
@RestController
@RequestMapping("/store/log")
public class StoreLogController extends BaseController
{
    @Autowired
    private IStoreLogService storeLogService;

    /**
     * 查询库房日志列表
     */
    @PreAuthorize("@ss.hasPermi('store:log:list')")
    @GetMapping("/list")
    public TableDataInfo list(StoreLogVO storeLog)
    {
        startPage();
        List<StoreLogVO> list = storeLogService.selectStoreLogList(storeLog);
        return getDataTable(list);
    }

    /**
     * 查询库房日志列表2
     */
    @PreAuthorize("@ss.hasPermi('store:log:list')")
    @GetMapping("/list1")
    public TableDataInfo list2(StoreLogVO storeLogVO)
    {
        startPage();
        PageDomain pageDomain = new PageDomain();
        pageDomain.setPageSize(10000);
        startPage();
        List<StoreLog> list = storeLogService.selectStoreLogList1(storeLogVO);
        return getDataTable(list);
    }
    /**
     * 导出库房日志列表
     */
    @PreAuthorize("@ss.hasPermi('store:log:export')")
    @Log(title = "库房日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StoreLogVO storeLog)
    {
        List<StoreLogVO> list = storeLogService.selectStoreLogList(storeLog);
        ExcelUtil<StoreLogVO> util = new ExcelUtil<StoreLogVO>(StoreLogVO.class);
        util.exportExcel(response, list, "库房日志数据");
    }

    /**
     * 获取库房日志详细信息
     */
    @PreAuthorize("@ss.hasPermi('store:log:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(storeLogService.selectStoreLogById(id));
    }

    /**
     * 新增库房日志
     */
    @PreAuthorize("@ss.hasPermi('store:log:add')")
    @Log(title = "库房日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StoreLog storeLog)
    {
        return toAjax(storeLogService.insertStoreLog(storeLog));
    }

    /**
     * 修改库房日志
     */
    @PreAuthorize("@ss.hasPermi('store:log:edit')")
    @Log(title = "库房日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StoreLog storeLog)
    {
        return toAjax(storeLogService.updateStoreLog(storeLog));
    }

    /**
     * 删除库房日志
     */
    @PreAuthorize("@ss.hasPermi('store:log:remove')")
    @Log(title = "库房日志", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(storeLogService.deleteStoreLogByIds(ids));
    }

    /**
     * 逻辑删除
     */
    @PreAuthorize("@ss.hasPermi('store:log:remove')")
    @Log(title = "库房日志", businessType = BusinessType.DELETE)
    @PutMapping("/{ids}")
    public AjaxResult logicRemove(@PathVariable Long[] ids)
    {
        return toAjax(storeLogService.logicDeleteStoreLogByIds(ids));
    }
}
